<?php
    // require_once(dirname(dirname(dirname(__FILE__))) . '/core.php');
    function str_build_link($param) {
        unset($_GET['act']);
        unset($_GET['op']);
        $data = $_GET;
        foreach ($param as $k => $v) {
            $data[$k] = $v;
        }
        $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . http_build_query($data);
        return $url;
    }

    if (true) {
//        $member_info = get_mobile_member_info();
        $model_xianshi_goods = Model('p_xianshi_goods');
        if (empty($_GET['type'])) {
            $_GET['type'] = 'xianshi';
        }
        if($_GET['sort'] == 1){
            $order = 'price desc';
        }
        else if($_GET['sort'] == 2){
            $order = 'price asc';
        }
        else{
            $order = '';
        }
        switch ($_GET['type']) {
            case 'xianshi':
                //获取限时折扣商品列表
                $condition = array();
                $condition['start_time'] = array(
                    'lt',
                    time()
                );
                $condition['end_time'] = array(
                    'gt',
                    time()
                );
                $condition['state'] = 1;
                if(!empty($order)){
                    $order = 'xianshi_' . $order;
                }
                $xianshi_goods_list = $model_xianshi_goods->getXianshiGoodsExtendList($condition,10,$order);
                if (!empty($xianshi_goods_list)) {
                    $pages = $model_xianshi_goods->showpage();
                    foreach ($xianshi_goods_list as $key => $goods) {
                        $xianshi_goods_list[$key]['goods_link'] = '/wap/tmpl/product_detail.php?goods_id=' . $goods['goods_id'];
                    }
                }
                else{
                    $pages = '';

                }
                break;

            case 'we_groupbuy':
                $m = Model('we_groupbuy');
                $condition['start_time'] = array(
                    'lt',
                    time()
                );
                $condition['end_time'] = array(
                    'gt',
                    time()
                );
                $condition['status'] = 0;
                $list = $m->where($condition)->page(10)->order($order)->select();
                $arr = [];

                if ($list) {
                    foreach ($list as $item) {
                        $ginfo = ml('goods')->find($item['goods_id']);
                        $arr[] = [
                            'goods_image' => $ginfo['goods_image'],
                            'xianshi_price' => $item['price'],
                            'goods_id' => $ginfo['goods_id'],
                            'goods_name' => $item['activity_name'],
                            'goods_link' => '/packages/we_groupbuy/goods_info.php?id=' . $item['id'].'&uid='.$_GET['uid'],
                            'max_person' => $item['max_person']
                        ];
                    }
                    $pages = $m->showpage();
                } else {
                    $pages = '';
                }
                $xianshi_goods_list = $arr;
                break;

            default:
                $xianshi_goods_list = [];
                break;
        }

        ?>
        <!doctype html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>

                <?php
                    $title = '';
                    switch ($_GET['type']) {
                        case 'xianshi':
                            $title = "限时折扣";
                            break;

                        case 'we_groupbuy':
                            $title = "微拼团";
                            break;
                    }
                    echo $title;
                ?>
            </title>
            <style>
                body {
                    font-family: 'Microsoft yahei' !important;
                }
            </style>
            <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
            <meta name="apple-mobile-web-app-capable" content="yes">
            <meta name="apple-mobile-web-app-status-bar-style" content="black">
            <meta name="format-detection" content="telephone=no">
            <link rel="stylesheet" type="text/css" href="/wap/e_tpl/css/base.css">
            <link rel="stylesheet" type="text/css" href="/wap/e_tpl/css/nctouch_member.css">
            <link rel="stylesheet" type="text/css" href="/wap/e_tpl/css/new.css">
            <link rel="stylesheet" type="text/css" href="/wap/css/font-awesome.min.css">
            <link rel="stylesheet" type="text/css" href="/wap/e_tpl/css/nctouch_products_list.css">

            <style>
                ._pager { padding: 2px !important; float: right !important; + float: none !important; + position: absolute !important; + right: 6 px !important; } ._pager ul { margin: 0 !important; padding: 0 !important; } ._pager ul li { line-height: 22px !important; display: inline !important; list-style-type: none !important; float: left !important; padding: 0px !important; color: #AAA !important; } ._pager li span { font-size: 13px !important; list-style-type: none !important; display: inline !important; float: left !important; padding: 3px 10px !important; margin: 0 1px 0 0 !important; } ._pager li a span, ._pager li a:visited span { color: #565D68 !important; text-decoration: none !important; cursor: pointer !important; -moz-border-radius: 4px !important; -webkit-border-radius: 4px !important; border-radius: 4px !important; } ._pager li a:hover span, ._pager li a:active span { color: #000 !important; background-color: #FFF !important; cursor: pointer !important; -khtml-opacity: .9 !important; -moz-opacity: 0.9 !important; -moz-box-shadow: 0 0 3px rgba(204, 204, 204, 0.5) !important; -webkit-box-shadow: 0 0 3px rgba(204, 204, 204, 0.5) !important; box-shadow: 0 0 3px rgba(204, 204, 204, 0.5) !important; } ._pager li span.currentpage { color: #FFF !important; font-weight: bold !important; background-color: #f60 !important; -moz-border-radius: 4px !important; -webkit-border-radius: 4px !important; border-radius: 4px !important; /*Firefox\Chrome\Safari\IE9\元素圆角效果*/ } #header { height: 1.95rem; } .header-wrap { margin-top: 0; } #nav_ul { width: 100%; } .goods-search-list-nav ul li { width: 50% !important; } #product_list { margin-top: 50px; }

                ._pager {
                    margin-top: 15px;
                }
            </style>
        </head>
        <body>
        <header id="header">
            <div class="header-wrap">
                <div class="header-l"><a href="member.php"> <i class="back"></i> </a></div>
                <div class="header-title">
                    <h1><?php echo $title; ?></h1>
                </div>
                <!-- <div class="header-r"> <a id="header-nav" href="address_opera.html"><i class="add"></i></a> </div> -->
            </div>
        </header>
        <div class="goods-search-list-nav">
            <ul id="nav_ul">
                <li><a href="javascript:void(0);" class="" id="sort_default">排序方式<i></i></a></li>
                <li><a href="javascript:void(0);" class="" id="choose_type">优惠类型<i></i></a></li>
            </ul>
        </div>
        <div id="sort_inner" class="goods-sort-inner" style="display: none"><span><a
                    href="<?php echo str_build_link(['sort' => '1']); ?>"
                    <?php if ($_GET['sort'] == 1){ ?>class="cur"<?php } ?>>价格从高到低<i></i></a></span> <span><a
                    href="<?php echo str_build_link(['sort' => '2']); ?>"
                    <?php if ($_GET['sort'] == 2){ ?>class="cur"<?php } ?>>价格从低到高<i></i></a></span>
        </div>
        <div id="type" class="goods-sort-inner" style="display: none">
            <span><a href="/wap/tmpl/member/promotion.php?type=xianshi"
                     <?php if ($_GET['type'] == 'xianshi'){ ?>class="cur"<?php } ?>>限时折扣<i></i></a></span> <span><a
                    href="/wap/tmpl/member/promotion.php?type=we_groupbuy" <?php if ($_GET['type'] == 'we_groupbuy'){?>class="cur"<?php }?>>微拼团<i></i></a></span>
        </div>
        <div style="height: 50px;"></div>
        <div id="product_list" class="list">
            <ul class="goods-secrch-list">
                <?php if ($xianshi_goods_list) { ?>
                    <?php
                    foreach ($xianshi_goods_list as $key => $value) {
                        ?>
                        <li class="goods-item" goods_id="<?php echo $value['goods_id']; ?>">
                <span class="goods-pic">
                    <a href="<?php echo $value['goods_link']; ?>"><img
                            src="<?php echo cthumb($value['goods_image'], '', $value['store_id']); ?>" alt=""></a>
                </span>
                            <dl class="goods-info">
                                <dt class="goods-name">
                                    <a href="<?php echo $value['goods_link']; ?>">
                                        <h4><?php echo $value['goods_name']; ?></h4>
                                    </a>
                                    <?php
                                        if ($_GET['type'] == 'we_groupbuy') {
                                            ?>
                                            <span class="goods-price">
                                        原价：￥<del><?php
                                                        $ginfo = ml('goods')->find($value['goods_id']);
                                                        echo $ginfo['goods_price'];
                                                    ?>
                                                </del>
                                    </span>
                                            <?php
                                        }
                                    ?>
                                </dt>
                                <?php
                                    if ($_GET['type'] == 'we_groupbuy') {
                                ?>
                                <dd class="goods-sale">
                                    <a href="<?php echo $value['goods_link'] ?>">
                                        <span class="goods-price" style="display: block;">
                                            <?php
                                                if ($_GET['type'] == 'we_groupbuy') {
                                                    echo $value['max_person']."人团";
                                                }
                                            ?>
                                        </span>
                                    </a>
                                </dd>
                                <?php
                                    }
                                ?>
                                <dd>
                                    <a href="<?php echo $value['goods_link'] ?>">
                                        <span class="goods-price" style="display: block;">
                                            <?php
                                            if ($_GET['type'] == 'we_groupbuy') {
                                                echo "团购价：";
                                            }
                                            ?>
                                            ￥<em><?php echo $value['xianshi_price']; ?></em>
                                        </span>
                                    </a>
                                </dd>
                            </dl>
                        </li>
                    <?php }
                } else { ?>
                    <div class="nctouch-norecord order">
                        <div class="norecord-ico"><i></i></div>
                        <dl>
                            <dt>没有相关商品</dt>
                            <dd></dd>
                        </dl>
                        <a href="/wap/tmpl/product_first_categroy.php" class="btn">随便逛逛</a>
                    </div>
                <?php } ?>
            </ul>
            <div class="_pager">
                <?php echo $pages; ?>
            </div>
        </div>
        <div style="height: 30px;"></div>
        <div id="footer"></div>
        <script type="text/javascript" src="/wap/e_tpl/js/zepto.min.js"></script>
        <script type="text/javascript" src="/wap/e_tpl/js/config.js"></script>
        <script type="text/javascript" src="/wap/e_tpl/js/template.js"></script>
        <script type="text/javascript" src="/wap/e_tpl/js/common.js"></script>
        <script type="text/javascript" src="/wap/e_tpl/js/simple-plugin.js"></script>
        <!-- <script type="text/javascript" src="/wap/js/tmpl/common-top.js"></script> -->
        <script type="text/javascript" src="/wap/e_tpl/js/tmpl/footer.js"></script>
        </body>
        </html>
        <script>
            $(function(){
                $("#sort_default").click(function() {
                    $(this).toggleClass("current");
                    $("#choose_type").removeClass("current");
                    $("#sort_inner").toggle();
                    $("#type").hide();
                });
                $("#choose_type").click(function() {
                    $(this).toggleClass("current");
                    $("#sort_default").removeClass("current");
                    $("#type").toggle();
                    $("#sort_inner").hide();
                });
            })
        </script>
    <?php } ?>
